import type { MapEmitType, MMapProps, UseMMapOptions } from '../types.ts'
import * as mars3d from 'mars3d'

export function initMMap<E extends MapEmitType, P extends MMapProps>(
  options: UseMMapOptions<E, P>,
) {
  const { emit, MapState, props } = options
  if (!props.elementId) return
  MapState.instance = new mars3d.Map(props.elementId, {
    scene: {
      center: { lat: 30.054604, lng: 108.885436, alt: 17036414, heading: 0, pitch: -90 },
    },
    terrain: {
      url: 'https://data.mars3d.cn/terrain',
      show: true,
    },
    basemaps: [
      {
        name: '天地图影像',
        icon: 'https://data.mars3d.cn/img/thumbnail/basemap/tdt_img.png',
        type: 'tdt',
        layer: 'img_d',
        show: true,
        isInitial: true, //表示初始地图图层， 在后续业务操作中不需要删除
      } as never,
    ],
  })
  emit('initMap', MapState.instance)
}
